package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.Permission;
import com.itheima.pojo.Permission;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


import java.util.List;
import java.util.Set;

public interface PermissionDao {
/*
    @Select("SELECT * FROM t_permission WHERE id IN(SELECT permission_id FROM t_role_permission WHERE role_id=#{role_id})")
    public Set<Permission> findPermission(Integer role_id);
    */

    public Set<Permission> findByRoleId(Integer roleId);

    @Insert("insert into t_permission(name,keyword,description,createDate,state) values (#{name},#{keyword},#{description},#{createDate},#{state})")
    public void  add(Permission permission);

    //    分页查询
    public Page<Permission> selectByCondition(String queryString);

    //删除检查项
    @Update("delete from t_permission where id = #{id}")
    public void  del(Integer id);

    //查询是否关联检查组
    @Select("select count(*) from t_role_permission where permission_id = #{permission_id}")
    public long findCountByPermissionId(Integer permissionId);


    //回显数据
    @Select("select * from t_permission where id = #{id}")
    public Permission  FindAll(Integer id);

    //    编辑检查项
    public void  edit(Permission permission);

    //    查询所有检查项数据
    @Select("select * from t_permission")
    List<Permission> findAll();


    @Select("SELECT  * FROM t_permission WHERE id IN(SELECT permission_id FROM t_role_permission WHERE role_id=#{role_id})")
    List<Permission> findPermissionId(int role_id);

}
